package com.wsg.lightaccounting.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wsg.lightaccounting.Model.AccountManager;
import com.wsg.lightaccounting.Model.RecordManager;
import com.wsg.lightaccounting.R;

import java.util.ArrayList;

/**
 * Created by dell-pc on 2016/11/22.
 */

public class ColorGridViewAdapter extends BaseAdapter{
    private ArrayList<Integer> colors;
    private Context mcontext;

    public ColorGridViewAdapter(Context context){
        mcontext = context;
        colors = new ArrayList<Integer>();
        for (int i = 0; i < 11; i++) {
            colors.add(i);
        }
    }
    @Override
    public int getCount() {
        return colors.size();
    }

    @Override
    public Object getItem(int position) {
        return colors.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ItemViewTag viewTag;

        if (convertView == null) {
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.color_view, null);
            viewTag = new ItemViewTag((ImageView) convertView.findViewById(R.id.color), (TextView) convertView.findViewById(R.id.color_num));
            convertView.setTag(viewTag);
        }
        else{
            viewTag = (ItemViewTag)convertView.getTag();
        }
        viewTag.mName.setText(String.valueOf(colors.get(position)));
        AccountManager.setAccountColor(mcontext,viewTag.mIcon,position);
        return convertView;
    }

    class ItemViewTag {
        protected ImageView mIcon;
        protected TextView mName;

        public ItemViewTag(ImageView icon, TextView name) {
            this.mName = name;
            this.mIcon = icon;
        }
    }
}
